/**
 * 注册流程状态
 */

 // 默认表单字段
 let formDefault = {
  phone_area_code:'855', //国家区域码
  account: '',
  code:''
}
 export const state = () => {
  return {
    form: {},
    exists: [], //已存在的用户列表
  }
 }

export const getters = {
  getFormData(state){
    return JSON.parse(JSON.stringify(formDefault));
  },
  getExists(state){
    return state.exists;
  },
  getCode (state) {
    return state.form.code;
  }
}

 export const mutations = {
  SET_EXISTS (state,list){
    state.exists = list || []
  },
  // 设置表单数据
  // 为防止同时存在email和phone的注册信息
  // 每次都与默认字段合并
  SET_FORM (state,form){
    state.form = Object.assign(JSON.parse(JSON.stringify(formDefault)),form || {})
  },

  SET_AREA_CODE (state,code) {
    state.form.phone_area_code = code;
  },

  SET_CODE (state, code) {
    state.form.code = code;
  }

 }
